/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.pa165.bookingmanager.rest.resource;

import cz.muni.fi.pa165.bookingmanager.adapters.HotelAdapter;
import cz.muni.fi.pa165.bookingmanager.dto.HotelDTO;
import cz.muni.fi.pa165.bookingmanager.exceptions.IllegalOrphanException;
import cz.muni.fi.pa165.bookingmanager.exceptions.NonexistentEntityException;
import cz.muni.fi.pa165.bookingmanager.exceptions.PreexistingEntityException;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;

/**
 *
 * @author Jiří Holuša
 */
@Path("/hotel")
@Stateless
public class HotelRESTFacade1 {

    @EJB
    private HotelAdapter hotelAdapter;
    

     public HotelRESTFacade1() {		
	    }		
	

    
    
    @POST
    @Consumes({"application/xml", "application/json"})
    public void create(HotelDTO hotel) throws IllegalOrphanException, PreexistingEntityException{
        hotelAdapter.createHotel(hotel);
    }

    @PUT    
    @Consumes({"application/xml", "application/json"})
    public void edit(HotelDTO hotel) throws NonexistentEntityException, IllegalOrphanException, PreexistingEntityException, Exception {
        hotelAdapter.updateHotel(hotel);
    }

    @POST
    @Path("delete")
    @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})	    
    public void remove(HotelDTO hotel) throws NonexistentEntityException, IllegalOrphanException {	
    hotelAdapter.deleteHotel(hotel);	
	    }
	


    @GET
    @Path("{id}")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public HotelDTO get(@PathParam("id") Long id) {
        return hotelAdapter.getHotelById(id);
    }   

    @GET
    @Path("allByName-{name}")    
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List<HotelDTO> findAllByName(@PathParam("name") String name) {
        List<HotelDTO> hotels = hotelAdapter.findHotelsByName(name);
        return hotels;
    }
    
    @GET
    @Path("allByCity-{city}")    
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List<HotelDTO> findAllByCity(@PathParam("city") String city) {
        List<HotelDTO> hotels = hotelAdapter.findHotelsByCity(city);
        return hotels;
    }
    
    @GET 
    @Path("all")
    @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
    public List<HotelDTO> findAll() {        
        List<HotelDTO> hotels = hotelAdapter.findAllHotels();
        return hotels;
    }
    
}
